﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Customer_Profile.eCardReport.DBDao;
using KVB.Common;
using System.Text;
using DevExpress.Data;
using DevExpress.Web.ASPxGridView;
using Customer_Profile.eCard.DBDao;

namespace Customer_Profile.eCardReport
{
    public partial class ReportTest : System.Web.UI.Page
    {
        DataSet dsResult = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            BindDataView();
            ASPxGridView1.GroupSummarySortInfo.Clear();
            ColumnSortOrder sortOrder = ColumnSortOrder.Descending;
            ASPxGridView1.GroupSummarySortInfo.AddRange(new ASPxGroupSummarySortInfo("cparty_name", ASPxGridView1.GroupSummary["real_count"], sortOrder));
        }

        private void BindDataView()
        {
            string strName = txtName.Text.Trim();
            try
            {
                dsResult = ReportDao.getCpartyData(strName);
                if (dsResult != null && dsResult.Tables.Count > 0)
                {
                    ASPxGridView1.DataSource = dsResult.Tables[0];
                    ASPxGridView1.DataBind();
                }
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("Maturity_BindDataView", ex.ToString());
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //ASPxGridViewExporter1.WriteXlsToResponse();
        }

        protected void ASPxGridView1_SummaryDisplayText(object sender, ASPxGridViewSummaryDisplayTextEventArgs e)
        {
            /*
            ASPxSummaryItem dxCount = ASPxGridView1.TotalSummary[0];
            decimal iCardCount = Convert.ToDecimal(ASPxGridView1.GetTotalSummaryValue(dxCount));
            decimal iAllCount = Convert.ToDecimal(dsResult.Tables[1].Rows[0][0].ToString());
            //string strTemp = ASPxGridView1.GetTotalSummaryValue(dx).ToString();
            if (e.Item == dxCount)
                e.Text +=" 续存率："+ Math.Round(iCardCount * 100 / iAllCount, 2).ToString() + "%";

            //lbAgainRatio.Text += (iCardCount * 100 / iAllCount).ToString() + "%";
            ASPxSummaryItem dxAmount = ASPxGridView1.TotalSummary[1];
            decimal iCardAmount = Convert.ToDecimal(ASPxGridView1.GetTotalSummaryValue(dxAmount));
            decimal iAllAmount = Convert.ToDecimal(dsResult.Tables[1].Rows[0][1].ToString());
            //lbAgainRatio.Text += "按金额计算：" + (iCardAmount * 100 / iAllAmount).ToString() + "%";
            if (e.Item == dxAmount)
                e.Text += " 续存率：" + Math.Round(iCardAmount * 100 / iAllAmount, 2).ToString() + "%";    
             * */
        }
    }
}